/*
 * Created on 2005-3-12
 *
 */
package bma.common.langutil.bean.impl;

import java.lang.reflect.Member;
import java.lang.reflect.Modifier;

import bma.common.langutil.bean.AccessType;
import bma.common.langutil.bean.BeanObjectProperty;
import bma.common.langutil.core.MType;

/**
 * 
 * @author guanzhong
 * @since 1.0 (imported from BMA.ESP Project)
 * 
 */
public abstract class BeanObjectPropertyAbstract implements BeanObjectProperty {

	private Member prototype;

	private MType type;

	private String name;

	private AccessType[] accessType;

	public BeanObjectPropertyAbstract() {
		super();
	}

	@Override
	public Member getPrototype() {
		return prototype;
	}

	public void setPrototype(Member m) {
		prototype = m;
	}

	/**
	 * @return Returns the accessType.
	 */
	public AccessType[] getAccessType() {
		return accessType;
	}

	/**
	 * @param accessType
	 *            The accessType to set.
	 */
	public void setAccessType(AccessType[] accessType) {
		this.accessType = accessType;
	}

	@Override
	public Class getDeclaringType() {
		return this.prototype == null ? null : this.prototype
				.getDeclaringClass();
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public MType getType() {
		if (type != null)
			return type;
		return null;
	}

	/**
	 * @param name
	 *            The name to set.
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @param type
	 *            The type to set.
	 */
	public void setType(MType type) {
		this.type = type;
	}

	@Override
	public boolean accessible(AccessType type) {
		if (accessType == null)
			return true;
		for (AccessType t : accessType) {
			if (t.equals(type))
				return true;
		}
		return false;
	}

	public int getModifiers() {
		return Modifier.PUBLIC;
	}

	@Override
	public String toString() {
		return name + ":" + type;
	}
}
